﻿Public Class XLPhongBan
    Private kn As New KNPhongBan
    Private nv As New KNNhanVien
    Public Function LayDSPB() As DataTable
        Return kn.DSPB
    End Function
    Public Function LayDSNV() As List(Of DTO_NhanVienCT.NhanVien)
        Return nv.DSNhanVien
    End Function
    Public Function SavePB(ByVal data As DataTable) As Boolean
        Return kn.SavePB(data)
    End Function
    Public Function TimTenNV(ByVal str As String, ByVal dsnv As List(Of DTO_NhanVienCT.NhanVien)) As String
        For Each n As DTO_NhanVienCT.NhanVien In dsnv
            If n.MaNV = str Then
                str = n.HoTen
                Exit For
            End If
        Next
        Return str
    End Function
    Public Function TimMaNV(ByVal str As String, ByRef manv As String, ByVal dsnv As List(Of DTO_NhanVienCT.NhanVien)) As Boolean
        Dim kq As Boolean = False
        For Each n As DTO_NhanVienCT.NhanVien In dsnv
            If n.HoTen = str Then
                manv = n.MaNV
                kq = True
                Exit For
            End If
        Next
        Return kq
    End Function
    Public Function Ktrathem(ByVal pb As DTO_PhongBan.PhongBan, ByVal data As DataTable, ByVal dau As Integer) As Boolean
        Dim kq As Boolean = False
        'If pb.TruongPhong = "" Then Return True
        If dau = 1 Then
            If pb.TenPhong = "" Then kq = True
            For Each dr As DataRow In data.Rows
                If pb.MaPB = dr("MaPB") Then ' Or pb.TruongPhong = dr("MaTRP") 
                    kq = True
                    Exit For
                End If
            Next
        Else 'kiem tra capnhat
            If pb.NgayNChuc = "" Then kq = True
            For Each dr As DataRow In data.Rows
                If pb.TruongPhong = Convert.ToString(dr("MaTRP")) Then
                    kq = True
                    Exit For
                End If
            Next
        End If
        Return kq
    End Function
    Public Function BUS_LayDSPB() As List(Of DTO_PhongBan.PhongBan)
        Dim ds As New List(Of DTO_PhongBan.PhongBan)
        Dim kn As New KNPhongBan
        Dim data As New DataTable
        data = kn.DSPB()
        For Each dr As DataRow In data.Rows
            Dim p As New DTO_PhongBan.PhongBan
            p.MaPB = dr("MaPB")
            p.TenPhong = dr("TenPB")
            ds.Add(p)
        Next
        Return ds
    End Function

End Class
